package com.prometheus.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author: Alan
 * @date: 2021/5/18 13:24
 */
public class Utils {

    /**
     * 清理命名空间，转成驼峰法
     * @param nameSpace
     * @return
     */
    public static String clearNamespace(String nameSpace) {
        if (nameSpace == null) {
            return "Default";
        }
        StringBuffer sb = new StringBuffer();
        Pattern p = Pattern.compile("[_-](\\w)");
        Matcher matcher = p.matcher(nameSpace);
        while (matcher.find()) {
            matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
        }
        matcher.appendTail(sb);
        return sb.toString().replaceAll("[_-]", "");
    }
}
